package lancs.mobilemedia.core.ui.screens;

import java.util.Vector;

import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.List;

import lancs.mobilemedia.factories.FavouritesSPLFactory;
import lancs.mobilemedia.factories.SPLFactory;
import lancs.mobilemedia.factories.SortingSPLFactory;

public class PhotoListScreen extends List {

	CommandList list;

	private Vector splFactories;

	public PhotoListScreen() {
		super("Choose Items", Choice.IMPLICIT);
		init();
	}

	private void createFactories() {
		splFactories = new Vector();
		// if Sorting feature is enabled
		splFactories.addElement(new SortingSPLFactory());
		// if Sorting feature is enabled
		splFactories.addElement(new FavouritesSPLFactory());
	}

	private void init() {
		createFactories();
		createCommandList();
		initMenu();
	}

	public void createCommandList() {
		list = new PhotoListScreenCommandList();
		SPLFactory factory;
		for (int i = 0; i < splFactories.size(); i++) {
			factory = (SPLFactory) splFactories.elementAt(i);
			list = factory.createCommandList(list);
		}
	}

	public void initMenu() {
		Vector v = list.getList();
		for (int i = 0; i < v.size(); i++) {
			this.addCommand((Command) v.elementAt(i));
		}
	}
}